package com.ruoyi.kjy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.kjy.domain.CreateSpace;
import com.ruoyi.kjy.domain.TalentPerson;
import com.ruoyi.kjy.service.CreateSpaceService;
import com.ruoyi.kjy.service.TalentPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Objects;

/**
 * @Description:
 * @Author: Hi，Wang
 * @Date: 10/25,0025 21:08
 */

@RestController
@RequestMapping("/talentPerson")
public class TalentPersonController extends BaseController {


    @Autowired
    private TalentPersonService talentPersonService;

    @GetMapping("/list")
    public AjaxResult list(Long current, Long size, TalentPerson talentPerson) {
        QueryWrapper<TalentPerson> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(talentPerson);
        if (Objects.isNull(current))  {
            current = 1l;
        }
        if (Objects.isNull(size)) {
            size = 10l;
        }
        if (size >= 20l) {
            size = 20l;
        }
        return AjaxResult.success(talentPersonService.page(new Page<>(current, size), queryWrapper));
    }




    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(talentPersonService.getById(id));
    }


    @Log(title = "人才库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TalentPerson talentPerson) {
        talentPerson.setStatus(0);
        boolean save = talentPersonService.save(talentPerson);
        return toAjax(save);
    }

    @Log(title = "人才库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TalentPerson talentPerson) {
        return toAjax(talentPersonService.updateById(talentPerson));
    }

    @Log(title = "人才库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(talentPersonService.removeByIds(Arrays.asList(ids)));
    }


}
